package com.changgou.service.goods.controller;

import com.changgou.common.pojo.Result;
import com.changgou.common.pojo.StatusCode;
import com.changgou.goods.pojo.Goods;
import com.changgou.goods.pojo.Spu;
import com.changgou.service.goods.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Package: com.changgou.service.goods.controller
 * ClassName: SpuController
 * Description:
 *
 * @Author : 福森森
 * @Create : 2024/8/28 20:50
 */
@RequestMapping("/spu")
@RestController
public class SpuController {
    @Autowired
    private SpuService spuService;

    @PostMapping
    public Result<Spu> add(@RequestBody Goods goods) {
        spuService.add(goods);
        return new Result<>(true, StatusCode.OK,"添加成功");
    }

    @GetMapping("/{id}")
    public Result<Spu> findById(@PathVariable("id") String id) {
        Goods goods = spuService.findGoodsById(id);
        return new Result<>(true,StatusCode.OK,"查询成功",goods);
    }

    @PutMapping("/{id}")
    public Result<Spu> update(@PathVariable("id") String id, @RequestBody Goods goods) {
        spuService.updateByIdWiteObj(id,goods);
        return new Result<>(true,StatusCode.OK,"修改成功");
    }

    @PutMapping("/audit/{id}")
    public Result<Spu> audit(@PathVariable("id") String id) {
        spuService.audit(id);
        return new Result<>();
    }

    @PutMapping("/pull/{id}")
    public Result<Spu> pull(@PathVariable("id") String id) {
        spuService.pull(id);
        return new Result<>();
    }

    @PutMapping("/put/{id}")
    public Result<Spu> put(@PathVariable("id") String id) {
        spuService.put(id);
        return new Result<>();
    }

    @PutMapping("/delete/{id}")
    public Result<Spu> delete(@PathVariable("id") String id) {
        spuService.deleteById(id);
        return new Result<>();
    }

    @PutMapping("/restore/{id}")
    public Result<Spu> restore(@PathVariable("id") String id) {
        spuService.restore(id);
        return new Result<>();
    }

    @DeleteMapping("/realDelete/{id}")
    public Result<Spu> realDelete(@PathVariable("id") String id) {
        spuService.realDelete(id);
        return new Result<>();
    }
}






















